<?php
namespace App\Job;

use Hyperf\AsyncQueue\Annotation\AsyncQueueMessage;

use App\Query\ConfigQuery;

use App\Repository\UserRepository;

// 奖励
class PrizeJob
{
    /**
     * @AsyncQueueMessage
     */
    public function push($id, $money, $count)
    {
        // 获取用户
        $user = UserRepository::find($id);
        
        // 配置
        $config = ConfigQuery::get();
        
        // 销售奖
        (new Prize\Share($money, $config, $count))->run($user, '【' . $user->username . '】销售奖');
        
        // 复投
        if(!$count)
        {
            // 管理奖
            (new Prize\Manage($money, $config))->run($user, '【' . $user->username . '】管理奖');

            // 分红奖，从关系链中查找
            (new Prize\Red($money, $user->user_all, $config))->run('【' . $user->username . '】分红');
        }
        
        var_dump(date('Y-m-d H:i:s') . ' 完成: ' . $user->username . ' 奖金任务');
    }
}